package cn.gotom.core.service.impl;


import java.io.Serializable;
import java.util.List;

import cn.gotom.core.dao.GenericDao;
import cn.gotom.core.service.GenericService;

import com.google.inject.persist.Transactional;


public class GenericServiceImpl<T, PK extends Serializable> extends UniversalServiceImpl implements GenericService<T, PK>
{

	protected GenericDao<T, PK> genericDao;

	public GenericServiceImpl(final GenericDao<T, PK> genericDao)
	{
		super(genericDao);
		this.genericDao = genericDao;
	}

	@Override
	public boolean exists(PK id)
	{
		return genericDao.exists(id);
	}

	@Override
	public List<T> find(int maxResults, int firstResult)
	{
		return genericDao.find(maxResults, firstResult);
	}

	@Override
	public List<T> findAll()
	{
		return genericDao.findAll();
	}

	@Override
	public T get(String name, Object value)
	{
		return genericDao.get(name, value);
	}

	@Override
	public T get(PK id)
	{
		return genericDao.get(id);
	}

	@Override
	public long getCount()
	{
		return genericDao.getCount();
	}

	@Transactional
	@Override
	public void remove(PK id)
	{
		genericDao.remove(id);	
	}
	@Transactional
	@Override
	public void removeAll()
	{
		genericDao.removeAll();
	}
	@Transactional
	@Override
	public T save(T value)
	{
		return genericDao.save(value);
	}
}
